﻿package kit4j.ui.cs.swing.component;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import kit4j.ui.cs.FontStyle;

/**
 * 字体风格列表的单元格绘制组件，实现以对应的字体风格显示出字体风格名字的单元格。
 * 
 * @author MiniKnife
 * 
 */
public class JFontStyleListCellRenderer extends JLabel implements
		ListCellRenderer {

	private static final long serialVersionUID = 1L;

	public JFontStyleListCellRenderer() {
		super();
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		if (value != null) {
			FontStyle fs = (FontStyle) value;
			setText(fs.getName());
			setFont(list.getFont().deriveFont(fs.getValue()));
		}

		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}
		setEnabled(list.isEnabled());
		setOpaque(true);

		return this;
	}

}